package com.eagletsoft.mmproj.ui;


import com.eagletsoft.mmproj.R;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class GuideItemFragment extends Fragment implements OnClickListener{
	private static final String KEY_IMAGE_RES_ID = "GuideItemFragment:ImageResId";
    private int mImageResId;
    private ImageView mImageView;
    private Button btnCollection;
    private Button btnGoInto;
    
    /**
     * Factory method to generate a new instance of the fragment given an image
     * number.
     * 
     * @param imageNum
     *            The image number within the parent adapter to load
     * @return A new instance of ImageDetailFragment with imageNum extras
     */
    public static GuideItemFragment newInstance(int imageResId) {
        final GuideItemFragment f = new GuideItemFragment();
        f.mImageResId = imageResId;
        return f;
    }

    /**
     * Empty constructor as per the Fragment documentation
     */
    public GuideItemFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    	if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_IMAGE_RES_ID)) {
    		mImageResId = savedInstanceState.getInt(KEY_IMAGE_RES_ID);
		}
    	
    	// Inflate and locate the main ImageView
    	View v = null;
    	if(mImageResId == R.drawable.start_page){
    		v = inflater.inflate(R.layout.start_layout, container, false);
    		btnCollection = (Button) v.findViewById(R.id.btnCollection);
    		btnGoInto = (Button) v.findViewById(R.id.btnGoInto);
    		btnCollection.setOnClickListener(this);
    		btnGoInto.setOnClickListener(this);
    	} else {
    		v = inflater.inflate(R.layout.guide_layout, container, false);
    	}
    	
        mImageView = (ImageView) v.findViewById(R.id.mmGuide);
        mImageView.setImageResource(mImageResId); 
        return v;
    }
    
    @Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putInt(KEY_IMAGE_RES_ID, mImageResId);
	}
    
    @Override
    public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnCollection:

			break;
		case R.id.btnGoInto:
			Intent intent = new Intent();
			intent.setClass(getActivity(),HomeActivity.class);
			startActivity(intent);
			getActivity().finish();
			break;
		default:
			break;
		}
    }

}
